package fr.esgi.utils;



import java.io.File;

public class Repertoire {

	String projet;
	String livrable;
	String path="ges/";

	public Repertoire(String projet,String livrable){
		//path="/Users/antoine/Documents/ges/";
		this.projet=projet;
		this.livrable=livrable;
	}
	
	public Repertoire(){
		super();
		
	}
	public void createRepertoireGroupe(){
		boolean repDejaExistant = false;
		File f = new File(path);
		String[] contenuSdCard = f.list();
		int i=0;
		while(i<contenuSdCard.length && !repDejaExistant){
			if(contenuSdCard[i].compareTo(path+"/"+projet)==0)
				repDejaExistant = true;
			i++;
		}
		File rep = new File(path+"/"+projet);
		if(!repDejaExistant)
			rep.mkdirs();
		File rep2 = new File(path+"/"+projet+"/"+livrable);
			rep2.mkdirs();
	}
	public void createRepertoire(){
		File f = new File(path);
		f.mkdirs();
		boolean repDejaExistant = false;
		
		String[] contenuSdCard = f.list();
		int i=0;
		while(i<contenuSdCard.length && !repDejaExistant){
			if(contenuSdCard[i].compareTo(path+"/"+projet)==0)
				repDejaExistant = true;
			i++;
		}
		File rep = new File(path+"/"+projet);
		if(!repDejaExistant)
			rep.mkdirs();
		File rep2 = new File(path+"/"+projet+"/"+livrable);
			rep2.mkdirs();
	}
	
	public String[] listFiles(String projet,String livrable){
		File f = new File(path+projet+"/"+livrable);
		String[] arrayFiles = f.list();
		return arrayFiles;
	}
	public void deleteFile(String projet,String livrable,String file){
		File f = new File(path+projet+"/"+livrable+"/"+file);
		f.delete();
	}
	public void createRepertoireGroupe(String projet,String livrable,String groupe){
		File f = new File(path+projet+"/"+livrable+"/"+groupe);
		f.mkdir();
	}
}
